package cn.edu.zzu.demo01Thread;

public class TestStateThread07 implements  Runnable{

    public static void main(String[] args) throws InterruptedException {

        Thread a = new Thread(new TestStateThread07(), "a");

        //new  ， NEW ,新生状态
        Thread.State state = a.getState();
        System.out.println(state);

        //开启线程， RUNNABLE 运行状态
        a.start();
        state = a.getState();
        System.out.println(state);

        //子线程睡眠  ，TMED_WAITING 阻塞状态
        while (a.getState() != Thread.State.TERMINATED){
            Thread.sleep(1);
            state = a.getState();
            System.out.println(state);
        }

        //循环结束后，子线程a 死亡，状态变更为 TERMINATED terminated
        state = a.getState();
        System.out.println(state);
    }

    @Override
    public void run() {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
